DB2分区表数据迁移步骤

您所在的位置:网站首页 db2 分区 DB2分区表数据迁移步骤

DB2分区表数据迁移步骤

#DB2分区表数据迁移步骤| 来源: 网络整理| 查看: 265

1.业务背景

       交易表存储了3个月交易数据,单表数据量达到了2亿条左右。此前为解决交易表数据量过大问题,已将联机交易表创建为分区

表,但随着交易量的增长,分区表也不能完全解决单表数据量过大的问题。为进一步解决交易表数据量过大,提升联机交易处理性

能,为当前表创建了历史表(也创建为分区表),且设定当前表仅保留15天数据,历史表保留2.5个月的数据。

2. 分区表数据移植步骤

在移植分区表数据之前,需要保证历史表和当前表的表结构完全一致(包含字段结构和索引)。

1) 从当前表detach需要移植的分区数据

alter table detach partition into table

2) 为临时表添加索引

为保证detach下来的临时表能快速的添加到历史表中,需要为临时表添加索引。(若不添加索引,将临时表添加到历史表时,历史表会重组整张表的索引,添加速度会很慢)。

创建索引命令如下:

create index on ( asc) allow reverse scans

3) 将临时表attach到历史表

alter table attach partition starting('YYYYMMDD') inclusive ending('YYYYMMDD') inclusive

from table

4)  重新创建当前表PART0000分区

PART0000分区为当前表的下边界分区,下边界分区为当前表的最小边界分区,因当前表detach了一个分区,需要重新创建

PART0000分区。创建命令如下:

alter table add partition PART0000 starting(MINVALUE)

5)对当前表做RUNSTATS

对当前表做runstats,如果表数据量过大,可抽样做。

runstats on table with distribution and sampled detailed indexes all tablesample system(10)

6)  如果当前表涉及到存储过程,需要设置存储过程生效并rebind

call sysproc.admin_revalidate_db_objects()

db2  rebind  P1368868893

如果不重新绑定存储过程,可能会导致存储过程执行失败。

7)  对历史表数据做一致性检查

set integrity for all  immediate unchecked

8)  查看历史表分区可用性

db2 describe data partitions for table show detail

9)  对历史表做runstats

runstats on table with distribution and sampled detailed indexes all tablesample system(30)

indexsample system(50)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3